/**
 * @Author：ming
 * @Date：2023/9/26 4:55 PM
 * @Filename：Lc228
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 */
public class Lc228 {
    public List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        int len = nums.length;

        int i = 0;
        int start = 0;
        int end = 0;
        while (i<len){
            if(i==len-1){
                StringBuilder sb = new StringBuilder();
                if(end==start){
                    sb.append(nums[i]);
                }else {
                    sb.append(nums[start]).append("->").append(nums[end]);
                }
                list.add(sb.toString());
            }

            if(nums[i+1]-nums[i]==1){
                end++;
            }else {
                StringBuilder sb = new StringBuilder();
                if(end==start){
                    sb.append(nums[i]);
                }else {
                    sb.append(nums[start]).append("->").append(nums[end]);
                }
                list.add(sb.toString());
                start = end+1;
                end = end+1;

            }
            i++;
        }

        return list;
    }
}
